<?php

include 'DBconn.php';

class DeliveryOrderMaster {

    public function getDoItemsForInvoice($customerFk)
	{
        $ret = array();
        $query = "Select dh.serialnumber,dh.delivery_order_code,dh.delivery_order_date,dh.customer_serialnumber_fk,dd.detserialnumber,dd.pro_serialnumber_fk,dd.delivered_qty,sh.sales_con_code,sd.price_per_unit,sd.base_currency_detserialnumber_fk,sh.current_rate,cd.currency_value,ph.pro_name,ph.part_number,ph.pro_description,ph.model_no,sd.pro_detserialnumber,prd.currency_serialnumber,prd.markup_type,prd.listprice,prd.discount,prd.markup1,prd.markup2,prd.markup3,prd.markup4,prd.markup5,prd.markup6,prd.default_price from delivery_order_pro_details as dd LEFT JOIN delivery_order_header as dh ON 
		dh.activestatus=1 and dh.serialnumber=dd.delivery_order_fk LEFT JOIN  sales_conformation_details as sd ON sd.activestatus=1 and sd.detserialnumber=dd.sc_detserialnumber_fk LEFT JOIN sales_conformation_header as sh ON sh.activestatus=1 and sh.serialnumber=sd.sc_serialnumber_fk LEFT JOIN product_details as prd ON prd.pro_detserialnumber=sd.pro_detserialnumber LEFT JOIN product_header as ph ON ph.serialnumber=sd.pro_serialnumber_fk and ph.activestatus=1 LEFT JOIN currency_detail as cd ON cd.detserialnumber=sd.base_currency_detserialnumber_fk and cd.to_currency_fk=prd.currency_serialnumber 
		where dd.activestatus=1 and dd.is_invoiced=0 and dd.delivery_order_fk IN(Select serialnumber from delivery_order_header as dh where dh.activestatus=1 and dh.customer_serialnumber_fk='$customerFk') ORDER BY dd.delivery_order_fk";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s))
		{
            $temp = new VoDOHeaderList();
            $temp->do_serialnumber = (int) $row->serialnumber;
            $temp->delivery_order_code = $row->delivery_order_code;
            $temp->delivery_order_date = $row->delivery_order_date;
            $temp->customer_serialnumber_fk = (int) $row->customer_serialnumber_fk;
			$temp->do_detserialnumber = (int) $row->detserialnumber;
			$temp->price_per_unit = round(($row->price_per_unit * $row->current_rate),4);
            $temp->pro_serialnumber_fk = (int) $row->pro_serialnumber_fk;
			$temp->pro_detserialnumber = (int) $row->pro_detserialnumber;
			$temp->base_currency_detserialnumber_fk = (int) $row->base_currency_detserialnumber_fk;
            $temp->delivered_qty = (int) $row->delivered_qty;
			$temp->sales_con_code = $row->sales_con_code;
			$temp->pro_name = $row->pro_name;
			$temp->part_number = $row->part_number;
			$temp->pro_description = $row->pro_description;
			
			$m1 = (double)$row->markup1;
			$m2 = (double)$row->markup2;
			$m3 = (double)$row->markup3;
			$m4 = (double)$row->markup4;
			$m5 = (double)$row->markup5;
			$m6 = (double)$row->markup6;
			
			$listprice = (double)$row->listprice;
			$discount = (double)$row->discount;
		
			$base_currency_value =(double)$row->currency_value;
			$netprice = round(($listprice - (($discount/100)*$listprice)),2);
			
			$costPrice = $netprice * $base_currency_value;
			$other_price = $costPrice / $row->current_rate;
			
			$price1=0;
			$price2=0;
			$price3=0;
			$price4=0;
			$price5=0;
			$price6=0;
			
			if($row->markup_type!='Net Markup')
			 {
				$price1 = round(($costPrice/(1-($m1/100))),4);
				$price2 = round(($costPrice/(1-($m2/100))),4);
				$price3 = round(($costPrice/(1-($m3/100))),4);
				$price4 = round(($costPrice/(1-($m4/100))),4);
				$price5 = round(($costPrice/(1-($m5/100))),4);
				$price6 = round(($costPrice/(1-($m6/100))),4);
			 }else{
				$price1 = round(($costPrice*(1+($m1/100))),4);
				$price2 = round(($costPrice*(1+($m2/100))),4);
				$price3 = round(($costPrice*(1+($m3/100))),4);
				$price4 = round(($costPrice*(1+($m4/100))),4);
				$price5 = round(($costPrice*(1+($m5/100))),4);
				$price6 = round(($costPrice*(1+($m6/100))),4);
			 }
			 
			 $priceList = array();

            $priceObj1 = new VOPrice();
            $priceObj1->sgd_price = (double)$price1;
			$priceObj1->other_price = (double)$price1;
            $priceObj1->hilight = 0;
            if ($row->default_price == 'Price A') {
                $priceObj1->hilight = 1;
            }
            $priceList[] = $priceObj1;

            $priceObj2 = new VOPrice();
            $priceObj2->sgd_price = (double)$price2;
			$priceObj2->other_price = (double)$price2;
            $priceObj2->hilight = 0;
            if ($row->default_price == 'Price B') {
                $priceObj2->hilight = 1;
            }
            $priceList[] = $priceObj2;

            $priceObj3 = new VOPrice();
            $priceObj3->sgd_price = (double)$price3;
			$priceObj3->other_price = (double)$price3;
            $priceObj3->hilight = 0;
            if ($row->default_price == 'Price C') {
                $priceObj3->hilight = 1;
            }
            $priceList[] = $priceObj3;

            $priceObj4 = new VOPrice();
            $priceObj4->sgd_price = (double)$price4;
			$priceObj4->other_price = (double)$price4;
            $priceObj4->hilight = 0;
            if ($row->default_price == 'Price D') {
                $priceObj4->hilight = 1;
            }
            $priceList[] = $priceObj4;

            $priceObj5 = new VOPrice();
            $priceObj5->sgd_price = (double)$price5;
			$priceObj5->other_price = (double)$price5;
            $priceObj5->hilight = 0;
            if ($row->default_price == 'Price E') {
                $priceObj5->hilight = 1;
            }
            $priceList[] = $priceObj5;

            $priceObj6 = new VOPrice();
            $priceObj6->sgd_price = (double)$price6;
			$priceObj6->other_price = (double)$price6;
            $priceObj6->hilight = 0;
            if ($row->default_price == 'Price F') {
                $priceObj6->hilight = 1;
            }
            $priceList[] = $priceObj6;

            $temp->price_list = $priceList;
            $temp->default_price = $row->default_price;
            $temp->isSelected = false;
            $ret[] = $temp;
        }
        return $ret;
    }

    public function addNewDeliveryOrder($VObject) 
	{
        $last_id = 0;
        $product_array = array();
		
        $delivery_order_code = $this->generateDoCode();
		
        $query = "Insert Into delivery_order_header(delivery_order_code,customer_serialnumber_fk,total_qty,delivery_order_date,do_remarks,cre_userid_fk,cre_datetime,activestatus) VALUES ('$delivery_order_code','$VObject->customer_serialnumber_fk','$VObject->total_qty','$VObject->delivery_order_date','$VObject->do_remarks','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
        if ($s) 
		{
            $last_id = mysql_insert_id();
			
            foreach ($VObject->pro_serialnumber_fk as $r => $pro_serialnumber_fk) 
			{
				$sc_serialnumber = mysql_real_escape_string($VObject->sc_serialnumber[$r]);
			    $sc_detserialnumber_fk = mysql_real_escape_string($VObject->sc_detserialnumber_fk[$r]);
                $sc_qty = mysql_real_escape_string($VObject->sc_qty[$r]);
				$delivered_qty = mysql_real_escape_string($VObject->delivered_qty[$r]);
                $warehouse_serialnumber_fk = 0;//mysql_real_escape_string($VObject->warehouse_serialnumber_fk[$r]);
				
				$po_detserialnumberArr = array();
				foreach($VObject->po_detserialnumber[$r] as $m => $po_detserialnumber)
				{
				  $po_detserialnumberArr[] = $po_detserialnumber;
				}
				
				$product_array = $this->checkProductStatus($sc_detserialnumber_fk,$pro_serialnumber_fk);
				
                if($product_array[1] != "FULLY SATISFIED") 
				{
					$query2 = "insert into delivery_order_pro_details(delivery_order_fk,sc_detserialnumber_fk,pro_serialnumber_fk,sc_qty,delivered_qty,warehouse_serialnumber_fk,is_invoiced,cre_userid_fk,cre_datetime,activestatus) values('$last_id','$sc_detserialnumber_fk','$pro_serialnumber_fk','$sc_qty','$delivered_qty','$warehouse_serialnumber_fk',0,'$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
					$s2 = mysql_query($query2) or die(mysql_error());
                    $do_detserialnumber = mysql_insert_id();
					
					$product_array = $this->checkProductStatus($sc_detserialnumber_fk,$pro_serialnumber_fk);
					
					$query3 = "update sales_conformation_details  set pro_status='$product_array[1]' where detserialnumber='$sc_detserialnumber_fk' and pro_serialnumber_fk='$pro_serialnumber_fk' and activestatus=1";
                    mysql_query($query3) or die(mysql_error());
					
                    $this->updateStockAfterDo($sc_detserialnumber_fk,$po_detserialnumberArr,$do_detserialnumber,$pro_serialnumber_fk,$delivered_qty,$VObject->delivery_order_date);
					
                    $trans_status = $this->checkSCStatus($sc_serialnumber);
					
					$VObjectTR = new VoTrasactionMaster();
					$VObjectTR->gr_do_detserialnumber_fk = $do_detserialnumber;
					$VObjectTR->po_sc_detserialnumber_fk = $sc_detserialnumber_fk;
					$VObjectTR->pro_serialnumber_fk = $pro_serialnumber_fk;
					$VObjectTR->trans_pro_qty = $delivered_qty;
					$VObjectTR->pro_status = $product_array[1];
					$VObjectTR->trans_status = $trans_status;
					$VObjectTR->warehouse_serialnumber_fk = $warehouse_serialnumber_fk;
					$VObjectTR->trans_type = 0;
					$VObjectTR->trans_date = $VObject->delivery_order_date;
					$VObjectTR->cre_userid_fk = $VObject->cre_userid_fk;
					$VObjectTR->cre_datetime = $VObject->cre_datetime;
					$this->addNewTransactionOut($VObjectTR);
                }
            }
        }
    }

	public function addNewTransactionOut($VObjectTR) 
	{
        $query = "insert into stock_trans_details(gr_do_detserialnumber_fk,po_sc_detserialnumber_fk,pro_serialnumber_fk,trans_pro_qty,pro_status,trans_status,warehouse_serialnumber_fk,trans_type,trans_date,cre_userid_fk,cre_datetime,activestatus)values('$VObjectTR->gr_do_detserialnumber_fk','$VObjectTR->po_sc_detserialnumber_fk','$VObjectTR->pro_serialnumber_fk','$VObjectTR->trans_pro_qty','$VObjectTR->pro_status','$VObjectTR->trans_status','$VObjectTR->warehouse_serialnumber_fk','$VObjectTR->trans_type','$VObjectTR->trans_date','$VObjectTR->cre_userid_fk','$VObjectTR->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
    }
	
	public function updateStockAfterDo($sc_detserialnumber,$po_detserialnumberArr,$do_detserialnumber,$pro_serialnumber_fk,$delivery_order_qty,$do_date) 
	{
		$i=0;
		$balance_to_deliver = $delivery_order_qty;
        $isGRClosed = 0;
		$balance_on_GR_dup = 0;
		$balance_on_GR_ori = 0;
		$last_grn_detserialnumber=0;
		$warehouse_serialnumber_fk = 0;
		$pre_allocated_qty = 0;
        $isFilled = true;
		$toGet = true;

		$query = "Select IFNULL((Select IFNULL(Sum(pms.allocated_qty-(IFNULL((Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.po_detserialnumber_fk=pms.po_detserialnumber),0))),0) from po_map_sc as pms where pms.activestatus=1 and pms.po_detserialnumber=smp.po_detserialnumber and pms.self_sc=0 and pms.map_serialnumber<smp.map_serialnumber and pms.sc_detserialnumber IN(Select spms.sc_detserialnumber from po_map_sc as spms where spms.po_detserialnumber=smp.po_detserialnumber and spms.activestatus=1 and spms.self_sc=0 and (spms.sc_type=1 or spms.sc_type=3 or(spms.sc_type=2 and spms.map_serialnumber < (Select map_serialnumber from po_map_sc where activestatus=1 
		and self_sc=0 and sc_type=1 and po_detserialnumber=smp.po_detserialnumber and map_serialnumber>spms.map_serialnumber and map_serialnumber<=smp.map_serialnumber LIMIT 1))) and spms.map_serialnumber<smp.map_serialnumber)),0) as pre_allocated_qty from po_map_sc as smp where smp.activestatus=1 and smp.sc_detserialnumber='$sc_detserialnumber' and smp.po_detserialnumber='$po_detserialnumberArr[$i]' GROUP BY smp.sc_detserialnumber LIMIT 1";
		$result = mysql_query($query) or die(mysql_error());
		if($row = mysql_fetch_object($result))
		{
			$pre_allocated_qty = (int) $row->pre_allocated_qty;
		}
		
        while ($isFilled && $balance_to_deliver > 0) 
		{
			while($toGet && $balance_on_GR_dup==0)
			{
				$result1=0;
				$gotEnd = true;
				while($gotEnd)
				{
					$query1 = "Select gd.grn_detserialnumber,warehouse_serialnumber_fk,gd.received_qty - IFNULL((Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.grn_detserialnumber_fk=gd.grn_detserialnumber and gmd.po_detserialnumber_fk=gd.po_detserialnumber_fk),0) as available_stock from grn_detail as gd where gd.activestatus=1 and grn_detserialnumber 
					NOT IN(Select grn_detserialnumber_fk from gr_do where is_gr_closed=1 and current_gr_pro_qty=0 and po_detserialnumber_fk=gd.po_detserialnumber_fk and activestatus=1) and gd.po_detserialnumber_fk='$po_detserialnumberArr[$i]' and grn_detserialnumber>'$last_grn_detserialnumber' HAVING available_stock>0 ORDER BY gd.grn_detserialnumber ASC LIMIT 1";
					$result1 = mysql_query($query1) or die(mysql_error());
					if(mysql_num_rows($result1)==0)
					{
						$i++;
						$gotEnd = true;
					}else{$gotEnd = false;}
				}				
				if ($row1 = mysql_fetch_object($result1))
				{	
					$last_grn_detserialnumber = (int)$row1->grn_detserialnumber;
					$warehouse_serialnumber_fk = (int)$row1->warehouse_serialnumber_fk;
					$available_stock = (int)$row1->available_stock;
				
					if($available_stock <= $pre_allocated_qty)
					{
						$pre_allocated_qty = $pre_allocated_qty - $available_stock;
						$balance_on_GR_dup = 0;
						$toGet = true;
					}else{			
					
						$on_stock = $available_stock - $pre_allocated_qty;					
						$balance_from_po = 0;							
						
						$query_bal = "Select IFNULL((Select IFNULL(Sum(psc.allocated_qty-IFNULL((Select IFNULL(Sum(sgmd.do_pro_qty),0) from gr_do as sgmd where sgmd.activestatus=1 and sgmd.sc_detserialnumber_fk=smp.sc_detserialnumber and sgmd.po_detserialnumber_fk=smp.po_detserialnumber),0)),0) from po_map_sc as psc where psc.activestatus=1 and psc.sc_detserialnumber=smp.sc_detserialnumber and psc.po_detserialnumber=smp.po_detserialnumber),0) as balance_to_deliver from po_map_sc as smp where smp.activestatus=1 and smp.sc_detserialnumber='$sc_detserialnumber' and smp.po_detserialnumber='$po_detserialnumberArr[$i]' GROUP BY smp.sc_detserialnumber HAVING balance_to_deliver > 0 LIMIT 1";
						$result_bal = mysql_query($query_bal) or die(mysql_error());
						if ($row_bal = mysql_fetch_object($result_bal))
						{
						   $balance_from_po = (int)$row_bal->balance_to_deliver;
						}
						
						if($balance_from_po < $on_stock){
							$balance_on_GR_dup = $balance_from_po;
						}else{
							$balance_on_GR_dup = $on_stock;
						}
						
						$balance_on_GR_ori = $available_stock;
						$toGet = false;
					}
				}
			}
			
			$delivered_on_GR = 0;
			
            if ($balance_to_deliver <= $balance_on_GR_dup) 
			{
			
				if($balance_to_deliver <= $balance_on_GR_ori)
				{
				  $balance_on_GR_ori = $balance_on_GR_ori - $balance_to_deliver;
				}else{
				  $balance_on_GR_ori = 0;
				}
				
				$delivered_on_GR = $balance_to_deliver;
				$balance_on_GR_dup = $balance_on_GR_dup - $balance_to_deliver;
				$balance_to_deliver = 0;
            }else{
			
				if($balance_to_deliver <= $balance_on_GR_ori)
				{
				  $balance_on_GR_ori = $balance_on_GR_ori - $balance_to_deliver;
				}else{
				  $balance_on_GR_ori = 0;
				}
				
                $delivered_on_GR = $balance_on_GR_dup;
                $balance_to_deliver = $balance_to_deliver - $balance_on_GR_dup;
				$balance_on_GR_dup = 0;
            }
           
		    if ($balance_on_GR_ori > 0) 
		    {
			   $isGRClosed = 0;
            } else{
               $isGRClosed = 1;
            }
			
			if ($balance_to_deliver > 0) 
		    {
			   $isFilled = true;
			   $toGet = true;
            }else{
               $isFilled = false;
			   $toGet = false;
            }
			
			$s1 = mysql_query("Insert Into gr_do(po_detserialnumber_fk,grn_detserialnumber_fk,sc_detserialnumber_fk,do_detserialnumber_fk,warehouse_serialnumber_fk,pro_serialnumber_fk,current_gr_pro_qty,do_pro_qty,is_gr_closed,do_date,activestatus) values('$po_detserialnumberArr[$i]','$last_grn_detserialnumber','$sc_detserialnumber','$do_detserialnumber','$warehouse_serialnumber_fk','$pro_serialnumber_fk','$balance_on_GR_ori','$delivered_on_GR','$isGRClosed','$do_date',1)") or die(mysql_error());
		
			$query2 = "Select on_sale,sold from stock_header where pro_serialnumber='$pro_serialnumber_fk' and warehouse_serialnumber_fk='$warehouse_serialnumber_fk' and activestatus=1";
			$result2 = mysql_query($query2) or die(mysql_error());
			$row2 = mysql_fetch_object($result2);
			$on_sale = (int) $row2->on_sale;
			$sold = (int) $row2->sold;
	
			$on_sale = $on_sale - $delivered_on_GR;
			$sold = $sold + $delivered_on_GR;

			$query3 = "Update stock_header set on_sale='$on_sale',sold='$sold' where pro_serialnumber='$pro_serialnumber_fk' and 
			warehouse_serialnumber_fk='$warehouse_serialnumber_fk' and activestatus=1";
			mysql_query($query3) or die(mysql_error());
		
			$on_sale_det_qty = $delivered_on_GR;
			$sold_det_qty = $delivered_on_GR;
		
			$query4 = "Insert Into stock_details(warehouse_serialnumber_fk,trans_detserialnumber,trans_type,pro_serialnumber,on_hand,on_sale,in_order,sold,free_for_allocation,activestatus) values('$warehouse_serialnumber_fk','$do_detserialnumber',4,'$pro_serialnumber_fk',0,'$on_sale_det_qty',0,'$sold_det_qty',0,1)";
			mysql_query($query4) or die(mysql_error());
		}
    }
	
	public function editDeliveryOrder($VObject) 
	{
        $product_array = array();
        $query = "update delivery_order_header set customer_serialnumber_fk='$VObject->customer_serialnumber_fk',total_qty='$VObject->total_qty',delivery_order_date='$VObject->delivery_order_date',do_remarks='$VObject->do_remarks' where serialnumber='$VObject->serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
		
        if ($s) 
		{
			$query1 = "Select * from delivery_order_pro_details where delivery_order_fk='$VObject->serialnumber' and activestatus=1";
			$result1 = mysql_query($query1) or die(mysql_error());
			while($row1 = mysql_fetch_object($result1))
			{
				$this->deleteTransactionOut($row1->detserialnumber);
				$this->updateStcokBeforeEditDo($row1->detserialnumber,$row1->pro_serialnumber_fk);
			}
            mysql_query("Update delivery_order_pro_details set activestatus=0 where delivery_order_fk='$VObject->serialnumber'") or die(mysql_error());
            
            foreach ($VObject->pro_serialnumber_fk as $r => $pro_serialnumber_fk) 
			{
				$sc_serialnumber = mysql_real_escape_string($VObject->sc_serialnumber[$r]);
			    $sc_detserialnumber_fk = mysql_real_escape_string($VObject->sc_detserialnumber_fk[$r]);
                $sc_qty = mysql_real_escape_string($VObject->sc_qty[$r]);
				$delivered_qty = mysql_real_escape_string($VObject->delivered_qty[$r]);
                $warehouse_serialnumber_fk = 0;//mysql_real_escape_string($VObject->warehouse_serialnumber_fk[$r]);
				
				$po_detserialnumberArr = array();
				foreach($VObject->po_detserialnumber[$r] as $m => $po_detserialnumber)
				{
				  $po_detserialnumberArr[] = $po_detserialnumber;
				}
				
				$product_array = $this->checkProductStatus($sc_detserialnumber_fk,$pro_serialnumber_fk);
				
                if($product_array[1] != "FULLY SATISFIED") 
				{
					$query2 = "insert into delivery_order_pro_details(delivery_order_fk,sc_detserialnumber_fk,pro_serialnumber_fk,sc_qty,delivered_qty,warehouse_serialnumber_fk,is_invoiced,cre_userid_fk,cre_datetime,activestatus) values('$VObject->serialnumber','$sc_detserialnumber_fk','$pro_serialnumber_fk','$sc_qty','$delivered_qty','$warehouse_serialnumber_fk',0,'$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
					$s2 = mysql_query($query2) or die(mysql_error());
                    $do_detserialnumber = mysql_insert_id();
					
					$product_array = $this->checkProductStatus($sc_detserialnumber_fk,$pro_serialnumber_fk);
					
					$query3 = "update sales_conformation_details  set pro_status='$product_array[1]' where detserialnumber='$sc_detserialnumber_fk' and pro_serialnumber_fk='$pro_serialnumber_fk' and activestatus=1";
                    mysql_query($query3) or die(mysql_error());
					
                    $this->updateStockAfterDo($sc_detserialnumber_fk,$po_detserialnumberArr,$do_detserialnumber,$pro_serialnumber_fk,$delivered_qty,$VObject->delivery_order_date);
					
                    $trans_status = $this->checkSCStatus($sc_serialnumber);
					
					$VObjectTR = new VoTrasactionMaster();
					$VObjectTR->gr_do_detserialnumber_fk = $do_detserialnumber;
					$VObjectTR->po_sc_detserialnumber_fk = $sc_detserialnumber_fk;
					$VObjectTR->pro_serialnumber_fk = $pro_serialnumber_fk;
					$VObjectTR->trans_pro_qty = $delivered_qty;
					$VObjectTR->pro_status = $product_array[1];
					$VObjectTR->trans_status = $trans_status;
					$VObjectTR->warehouse_serialnumber_fk = $warehouse_serialnumber_fk;
					$VObjectTR->trans_type = 0;
					$VObjectTR->trans_date = $VObject->delivery_order_date;
					$VObjectTR->cre_userid_fk = $VObject->cre_userid_fk;
					$VObjectTR->cre_datetime = $VObject->cre_datetime;
					$this->addNewTransactionOut($VObjectTR);
                }
            }
        }
    }

	public function deleteTransactionOut($gr_do_detserialnumber_fk) 
	{
		//Function can be used to edit come delete
		
        $query = "update stock_trans_details set activestatus=0 where gr_do_detserialnumber_fk='$gr_do_detserialnumber_fk' and trans_type='0'";
        $s = mysql_query($query) or die(mysql_error());
	}
	
    public function updateStcokBeforeEditDo($do_detserialnumber,$pro_serialnumber_fk) 
	{
		$query1 = "Select on_sale,sold,warehouse_serialnumber_fk from stock_details where trans_detserialnumber='$do_detserialnumber' and trans_type=4 and activestatus=1";
        $s1 = mysql_query($query1) or die(mysql_error());
		while($row1 = mysql_fetch_object($s1))
		{
			$on_sale_det_qty = (int)$row1->on_sale;
			$sold_det_qty = (int)$row1->sold;
			$warehouse_serialnumber_fk = (int)$row1->warehouse_serialnumber_fk;
		
			$query2 = "Select on_sale,sold from stock_header where pro_serialnumber='$pro_serialnumber_fk' and warehouse_serialnumber_fk='$warehouse_serialnumber_fk' and activestatus=1";
			$s2 = mysql_query($query2) or die(mysql_error());
			$row2 = mysql_fetch_object($s2);
			$on_sale = $row2->on_sale;
			$sold = $row2->sold;
		
			$on_sale = $on_sale + $on_sale_det_qty;
			$sold = $sold - $sold_det_qty;

			$query3 = "Update stock_header set on_sale='$on_sale',sold='$sold' where pro_serialnumber='$pro_serialnumber_fk' and warehouse_serialnumber_fk='$warehouse_serialnumber_fk' and activestatus=1";
			mysql_query($query3) or die(mysql_error());
		}
		
		$query4 = "Update stock_details set activestatus=0 where trans_detserialnumber='$do_detserialnumber' and trans_type=4";
		mysql_query($query4) or die(mysql_error());
		
		$query5 = "Update gr_do set activestatus=0 where do_detserialnumber_fk='$do_detserialnumber'";
		mysql_query($query5) or die(mysql_error());
    }
	
	public function deleteDeliveryOrder($VObject) 
	{
		$query = "Update delivery_order_header set delivery_order_code=concat('Del-',delivery_order_code),cre_userid_fk='$VObject->cre_userid_fk',cre_datetime='$VObject->cre_datetime',activestatus=0 where serialnumber='$VObject->serialnumber'";
		mysql_query($query) or die(mysql_error());
		
        $query1 = "Select * from delivery_order_pro_details where delivery_order_fk='$VObject->serialnumber' and activestatus=1";
		$result1 = mysql_query($query1) or die(mysql_error());
		while($row1 = mysql_fetch_object($result1))
		{
			$this->deleteTransactionOut($row1->detserialnumber);
			$this->updateStcokBeforeEditDo($row1->detserialnumber,$row1->pro_serialnumber_fk);
			
			mysql_query("Update delivery_order_pro_details set activestatus=0 where detserialnumber='$row1->detserialnumber'") or die(mysql_error());
			
			$product_array = $this->checkProductStatus($row1->sc_detserialnumber_fk,$row1->pro_serialnumber_fk);
			$query3 = "Update sales_conformation_details set pro_status='$product_array[1]' where detserialnumber='$row1->sc_detserialnumber_fk' and pro_serialnumber_fk='$row1->pro_serialnumber_fk' and activestatus=1";
            mysql_query($query3) or die(mysql_error());
			
			$sc_serialnumber = 0;
			$res = mysql_query("Select sc_serialnumber_fk from sales_conformation_details where detserialnumber='$row1->detserialnumber'") or die(mysql_error());
			while($row = mysql_fetch_object($res)){
				$sc_serialnumber = (int)$row->sc_serialnumber_fk;
			}			
			$this->checkSCStatus($sc_serialnumber);
		}
    }
	
    public function getAllDeliveryOrder() 
	{
        $ret = array();
        $query = "Select dh.serialnumber,dh.delivery_order_code,dh.customer_serialnumber_fk,ch.client_name,dh.delivery_order_date,dh.total_qty,dh.do_remarks,
		dh.cre_userid_fk,dh.cre_datetime,dh.activestatus,ch.client_name from delivery_order_header as dh LEFT JOIN client_header as ch ON ch.activestatus=1 
		and ch.serialnumber=dh.customer_serialnumber_fk where dh.activestatus=1";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s)) 
		{
            $temp = new VoDeliveryOrder();
            $temp->serialnumber = (int) $row->serialnumber;
            $temp->delivery_order_code = $row->delivery_order_code;
            $temp->customer_serialnumber_fk = (int) $row->customer_serialnumber_fk;
			$temp->client_name = $row->client_name;
            $temp->delivery_order_date = date("d-m-Y", strtotime($row->delivery_order_date));
            $temp->total_qty = (int) $row->total_qty;
            $temp->do_remarks = $row->do_remarks;
            $temp->cre_userid_fk = (int) $row->cre_userid_fk;
            $temp->cre_datetime = $row->cre_datetime;
			$temp->activestatus = (boolean) $row->activestatus;
			
			$result = mysql_query("Select * from delivery_order_pro_details where activestatus=1 and is_invoiced=1 and delivery_order_fk='$row->serialnumber'") or die(mysql_error());
			if(mysql_num_rows($result)!=0){$temp->is_invoiced = 1;}else{$temp->is_invoiced = 0;}
	
            $query2 = "Select dd.detserialnumber,dd.delivery_order_fk,sh.sales_con_code,sd.sc_serialnumber_fk,dd.sc_detserialnumber_fk,dd.pro_serialnumber_fk,sd.pro_qty,dd.delivered_qty,dd.warehouse_serialnumber_fk,
			pro.pro_name,pro.part_number,pro.pro_description from delivery_order_pro_details as dd LEFT JOIN sales_conformation_details as sd ON sd.activestatus=1 and sd.detserialnumber=dd.sc_detserialnumber_fk LEFT 
			JOIN sales_conformation_header as sh ON sh.activestatus=1 and sh.serialnumber=sd.sc_serialnumber_fk LEFT JOIN product_header as pro ON pro.serialnumber=dd.pro_serialnumber_fk and pro.activestatus=1 
			where dd.delivery_order_fk='$row->serialnumber' and dd.activestatus=1";
            $s2 = mysql_query($query2) or die(mysql_error());
            while ($row2 = mysql_fetch_object($s2)) 
			{
				$temp->delivery_order_fk[] = (int) $row2->delivery_order_fk;
                $temp->do_detserialnumber[] = (int) $row2->detserialnumber;
                $temp->sc_detserialnumber_fk[] = (int) $row2->sc_detserialnumber_fk;
				$temp->sc_serialnumber[] = (int) $row2->sc_serialnumber_fk;
				$temp->sales_con_code[] = $row2->sales_con_code;
                $temp->pro_serialnumber_fk[] = (int) $row2->pro_serialnumber_fk;
				$temp->pro_name[] = $row2->pro_name;
				$temp->part_number[] = $row2->part_number;
				$temp->pro_description[] = $row2->pro_description;
                $temp->sc_qty[] = (double) $row2->pro_qty;
				$temp->delivered_qty[] = (int) $row2->delivered_qty;
                $temp->warehouse_serialnumber_fk[] = (int) $row2->warehouse_serialnumber_fk;
				
				$balance_to_sale = 0;
				$po_detserialnumberArr = array();
				
				$query_r = "Select pms.map_serialnumber,pms.po_detserialnumber,pms.sc_detserialnumber,pms.allocated_qty-(Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.po_detserialnumber_fk=pms.po_detserialnumber and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber') as balance_qty,(Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.po_detserialnumber_fk=pms.po_detserialnumber and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber') as delivered_qty from po_map_sc as pms LEFT JOIN po_details as pd ON pd.activestatus=1 and pd.po_detserialnumber=pms.po_detserialnumber where pms.activestatus=1 and 
				pms.sc_detserialnumber='$row2->sc_detserialnumber_fk' HAVING balance_qty>0 ORDER BY pms.map_serialnumber";
				$s_r = mysql_query($query_r) or die(mysql_error());
				while ($row_r = mysql_fetch_object($s_r)) 
				{					
					$reserved_qty = 0;
					
					$query3 = "Select (IFNULL((Select IFNULL(Sum(gd.received_qty-(IFNULL((Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.grn_detserialnumber_fk=gd.grn_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber'),0))),0) from grn_detail as gd where gd.activestatus=1 and gd.po_detserialnumber_fk=smp.po_detserialnumber),0) -  IFNULL((Select IFNULL(Sum(pms.allocated_qty-(IFNULL((Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.po_detserialnumber_fk=pms.po_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber'),0))),0) from po_map_sc as pms where pms.activestatus=1 and pms.po_detserialnumber=smp.po_detserialnumber and pms.self_sc=0 and pms.map_serialnumber<smp.map_serialnumber and pms.sc_detserialnumber IN(Select spms.sc_detserialnumber from po_map_sc as spms where spms.po_detserialnumber=smp.po_detserialnumber and spms.activestatus=1 and spms.self_sc=0 and (spms.sc_type=1 or spms.sc_type=3 or(spms.sc_type=2 and spms.map_serialnumber < (Select map_serialnumber from po_map_sc where activestatus=1 
					and self_sc=0 and sc_type=1 and po_detserialnumber=smp.po_detserialnumber and map_serialnumber>spms.map_serialnumber and map_serialnumber<=smp.map_serialnumber LIMIT 1))) and spms.map_serialnumber<smp.map_serialnumber)),0)) as on_stock,IFNULL((Select IFNULL(Sum(psc.allocated_qty-IFNULL((Select IFNULL(Sum(sgmd.do_pro_qty),0) from gr_do as sgmd where sgmd.activestatus=1 and sgmd.sc_detserialnumber_fk=smp.sc_detserialnumber and sgmd.po_detserialnumber_fk=smp.po_detserialnumber and sgmd.do_detserialnumber_fk!='$row2->detserialnumber'),0)),0) from po_map_sc as psc where psc.activestatus=1 and psc.sc_detserialnumber=smp.sc_detserialnumber and psc.po_detserialnumber=smp.po_detserialnumber),0) as balance_to_deliver from po_map_sc as smp where smp.activestatus=1 and smp.sc_detserialnumber='$row_r->sc_detserialnumber' and smp.po_detserialnumber='$row_r->po_detserialnumber' GROUP BY smp.sc_detserialnumber HAVING on_stock > 0 LIMIT 1";
					$s3 = mysql_query($query3) or die(mysql_error());
					if($row3 = mysql_fetch_object($s3))
					{
						$on_stock = (int)$row3->on_stock;
						$balance_to_deliver = (int)$row3->balance_to_deliver;
			
						if($balance_to_deliver <= $on_stock)
						{
							$reserved_qty = $balance_to_deliver;
						}else{$reserved_qty = $on_stock;}
						
						$po_detserialnumberArr[] = (int)$row_r->po_detserialnumber;
					}			
					
				   $balance_to_sale = $balance_to_sale + $reserved_qty;
				}
				
				$temp->reserved_qty[] = $balance_to_sale;
				$temp->po_detserialnumber[] = $po_detserialnumberArr;
            }
            $ret[] = $temp;
            mysql_free_result($s2);
        }
        mysql_free_result($s);
        return $ret;
    }

    public function getDeliveryOrderByCode($serialnumber) 
	{
        $query = "Select dh.serialnumber,dh.delivery_order_code,dh.customer_serialnumber_fk,ch.client_name,dh.delivery_order_date,dh.total_qty,dh.do_remarks,
		dh.cre_userid_fk,dh.cre_datetime,dh.activestatus,ch.client_name from delivery_order_header as dh LEFT JOIN client_header as ch ON ch.activestatus=1 
		and ch.serialnumber=dh.customer_serialnumber_fk where dh.activestatus=1 and dh.serialnumber='$serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
		$temp = new VoDeliveryOrder();
        while ($row = mysql_fetch_object($s)) 
		{
            $temp = new VoDeliveryOrder();
            $temp->serialnumber = (int) $row->serialnumber;
            $temp->delivery_order_code = $row->delivery_order_code;
            $temp->customer_serialnumber_fk = (int) $row->customer_serialnumber_fk;
			$temp->client_name = $row->client_name;
            $temp->delivery_order_date = date("d-m-Y", strtotime($row->delivery_order_date));
            $temp->total_qty = (int) $row->total_qty;
            $temp->do_remarks = $row->do_remarks;
            $temp->cre_userid_fk = (int) $row->cre_userid_fk;
            $temp->cre_datetime = $row->cre_datetime;
			$temp->activestatus = (boolean) $row->activestatus;
			
			$result = mysql_query("Select * from delivery_order_pro_details where activestatus=1 and is_invoiced=1 and delivery_order_fk='$row->serialnumber'") or die(mysql_error());
			if(mysql_num_rows($result)!=0){$temp->is_invoiced = 1;}else{$temp->is_invoiced = 0;}

            $query2 = "Select dd.detserialnumber,dd.delivery_order_fk,sh.sales_con_code,sd.sc_serialnumber_fk,dd.sc_detserialnumber_fk,dd.pro_serialnumber_fk,sd.pro_qty,dd.delivered_qty,dd.warehouse_serialnumber_fk,
			pro.pro_name,pro.part_number,pro.pro_description from delivery_order_pro_details as dd LEFT JOIN sales_conformation_details as sd ON sd.activestatus=1 and sd.detserialnumber=dd.sc_detserialnumber_fk LEFT 
			JOIN sales_conformation_header as sh ON sh.activestatus=1 and sh.serialnumber=sd.sc_serialnumber_fk LEFT JOIN product_header as pro ON pro.serialnumber=dd.pro_serialnumber_fk and pro.activestatus=1 
			where dd.delivery_order_fk='$row->serialnumber' and dd.activestatus=1";
            $s2 = mysql_query($query2) or die(mysql_error());
            while ($row2 = mysql_fetch_object($s2)) 
			{
				$temp->delivery_order_fk[] = (int) $row2->delivery_order_fk;
                $temp->do_detserialnumber[] = (int) $row2->detserialnumber;
                $temp->sc_detserialnumber_fk[] = (int) $row2->sc_detserialnumber_fk;
				$temp->sc_serialnumber[] = (int) $row2->sc_serialnumber_fk;
				$temp->sales_con_code[] = $row2->sales_con_code;
                $temp->pro_serialnumber_fk[] = (int) $row2->pro_serialnumber_fk;
				$temp->pro_name[] = $row2->pro_name;
				$temp->part_number[] = $row2->part_number;
				$temp->pro_description[] = $row2->pro_description;
                $temp->sc_qty[] = (double) $row2->pro_qty;
				$temp->delivered_qty[] = (int) $row2->delivered_qty;
                $temp->warehouse_serialnumber_fk[] = (int) $row2->warehouse_serialnumber_fk;
				
				$balance_to_sale = 0;
				$po_detserialnumberArr = array();
				
				$query_r = "Select pms.map_serialnumber,pms.po_detserialnumber,pms.sc_detserialnumber,pms.allocated_qty-(Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.po_detserialnumber_fk=pms.po_detserialnumber and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.do_detserialnumber_fk='$row2->detserialnumber') as balance_qty,(Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.po_detserialnumber_fk=pms.po_detserialnumber and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber') as delivered_qty from po_map_sc as pms LEFT JOIN po_details as pd ON pd.activestatus=1 and pd.po_detserialnumber=pms.po_detserialnumber where pms.activestatus=1 and 
				pms.sc_detserialnumber='$row2->sc_detserialnumber_fk' HAVING balance_qty>0 ORDER BY pms.map_serialnumber";
				$s_r = mysql_query($query_r) or die(mysql_error());
				while ($row_r = mysql_fetch_object($s_r)) 
				{					
					$reserved_qty = 0;
				
					$query3 = "Select (IFNULL((Select IFNULL(Sum(gd.received_qty-(IFNULL((Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.grn_detserialnumber_fk=gd.grn_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber'),0))),0) from grn_detail as gd where gd.activestatus=1 and gd.po_detserialnumber_fk=smp.po_detserialnumber),0) -  IFNULL((Select IFNULL(Sum(pms.allocated_qty-(IFNULL((Select IFNULL(Sum(gmd.do_pro_qty),0) from gr_do as gmd where gmd.activestatus=1 and gmd.sc_detserialnumber_fk=pms.sc_detserialnumber and gmd.po_detserialnumber_fk=pms.po_detserialnumber and gmd.do_detserialnumber_fk!='$row2->detserialnumber'),0))),0) from po_map_sc as pms where pms.activestatus=1 and pms.po_detserialnumber=smp.po_detserialnumber and pms.self_sc=0 and pms.map_serialnumber<smp.map_serialnumber and pms.sc_detserialnumber IN(Select spms.sc_detserialnumber from po_map_sc as spms where spms.po_detserialnumber=smp.po_detserialnumber and spms.activestatus=1 and spms.self_sc=0 and (spms.sc_type=1 or spms.sc_type=3 or(spms.sc_type=2 and spms.map_serialnumber < (Select map_serialnumber from po_map_sc where activestatus=1 
					and self_sc=0 and sc_type=1 and po_detserialnumber=smp.po_detserialnumber and map_serialnumber>spms.map_serialnumber and map_serialnumber<=smp.map_serialnumber LIMIT 1))) and spms.map_serialnumber<smp.map_serialnumber)),0)) as on_stock,IFNULL((Select IFNULL(Sum(psc.allocated_qty-IFNULL((Select IFNULL(Sum(sgmd.do_pro_qty),0) from gr_do as sgmd where sgmd.activestatus=1 and sgmd.sc_detserialnumber_fk=smp.sc_detserialnumber and sgmd.po_detserialnumber_fk=smp.po_detserialnumber and sgmd.do_detserialnumber_fk!='$row2->detserialnumber'),0)),0) from po_map_sc as psc where psc.activestatus=1 and psc.sc_detserialnumber=smp.sc_detserialnumber and psc.po_detserialnumber=smp.po_detserialnumber),0) as balance_to_deliver from po_map_sc as smp where smp.activestatus=1 and smp.sc_detserialnumber='$row_r->sc_detserialnumber' and smp.po_detserialnumber='$row_r->po_detserialnumber' GROUP BY smp.sc_detserialnumber HAVING on_stock > 0 LIMIT 1";
					$s3 = mysql_query($query3) or die(mysql_error());
					if($row3 = mysql_fetch_object($s3))
					{
						$on_stock = (int)$row3->on_stock;
						$balance_to_deliver = (int)$row3->balance_to_deliver;
			
						if($balance_to_deliver <= $on_stock)
						{
							$reserved_qty = $balance_to_deliver;
						}else{$reserved_qty = $on_stock;}
						
						$po_detserialnumberArr[] = (int)$row_r->po_detserialnumber;
					}			
					
				   $balance_to_sale = $balance_to_sale + $reserved_qty;
				}
				
				$temp->reserved_qty[] = $balance_to_sale;
				$temp->po_detserialnumber[] = $po_detserialnumberArr;
            }
          mysql_free_result($s2);
        }
       mysql_free_result($s);
       return $temp;
    }

    public function getAllTransactions() 
	{
        $ret = array();
        $query = "select * from stock_trans_details where activestatus=1";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s)) {
            $temp = new VoTrasactionMaster();
			$temp->serialnumber = (int) $row->serialnumber;
            $temp->gr_do_detserialnumber_fk = (int) $row->gr_do_detserialnumber_fk;
            $temp->po_sc_detserialnumber_fk = (int) $row->po_sc_detserialnumber_fk;
			$temp->pro_serialnumber_fk = (int) $row->pro_serialnumber_fk;
			$temp->trans_pro_qty = (int) $row->trans_pro_qty;
			$temp->pro_status = $row->pro_status;
            $temp->trans_status = $row->trans_status;
			$temp->warehouse_serialnumber_fk = (int) $row->warehouse_serialnumber_fk;
			$temp->trans_type = $row->trans_type;
            $temp->trans_date = $row->trans_date;
            $temp->cre_userid_fk = (int) $row->cre_userid_fk;
            $temp->cre_datetime = $row->cre_datetime;
            $temp->activestatus = (boolean) $row->activestatus;
			$ret[] = $temp;
        }
        mysql_free_result($s);
        return $ret;
    }

    public function generateDoCode() {
        $query = "select delivery_order_code from delivery_order_header where activestatus=1 order by serialnumber desc limit 1 ";
        $result = mysql_query($query) or die(mysql_error());
        if (mysql_num_rows($result)) {
            $row = mysql_fetch_array($result);
            $str = explode("DO", $row[0]);
            $num = intval($str[1]);
            $res = "DO" . ++$num;
        } else {
            $res = 'DO1001';
        }
        return $res;
    }

    public function checkSCStatus($sc_serialnumber) 
	{
        $num_rows = 0;
        $status_rows = 0;
        $status_rows_part = 0;
        $sc_status = "";
		
        $query = "Select pro_status from sales_conformation_details where sc_serialnumber_fk='$sc_serialnumber' and activestatus=1";
        $s2 = mysql_query($query) or die(mysql_error());
        $num_rows = mysql_num_rows($s2);
        while ($row2 = mysql_fetch_object($s2)) 
		{
            if ($row2->pro_status == "FULLY SATISFIED")
                $status_rows = $status_rows + 1;
            else if ($row2->pro_status == "PARTIALLY SATISFIED")
                $status_rows_part = $status_rows_part + 1;
        }
        if ($num_rows == $status_rows && $status_rows_part == 0)
            $sc_status = "FULLY SATISFIED";
        else if (($status_rows_part > 0 || $status_rows > 0 ) && $num_rows != $status_rows)
            $sc_status = "PARTIALLY SATISFIED";
        else if ($status_rows == 0 && $status_rows_part == 0)
            $sc_status = "CONFIRM";
			
        $query = "update sales_conformation_header set sales_con_status='$sc_status' where serialnumber='$sc_serialnumber' and activestatus=1";
        $s2 = mysql_query($query) or die(mysql_error());
		
        return $sc_status;
    }

    public function checkProductStatus($sc_detserialnumber_fk, $pro_serialnumber_fk) 
	{
        $delivered_qty = 0;
        $pro_status = "";
        $sc_qty = 0;
		
        $product_array = array();
		
        $query2 = "select delivered_qty,sc_qty from  delivery_order_pro_details where sc_detserialnumber_fk='$sc_detserialnumber_fk' and pro_serialnumber_fk='$pro_serialnumber_fk' and activestatus=1";
        $s2 = mysql_query($query2) or die(mysql_error());
        if (mysql_num_rows($s2)) 
		{
            while ($row = mysql_fetch_object($s2)) {
                $delivered_qty+=$row->delivered_qty;
                $sc_qty = $row->sc_qty;
            }
			
            $product_array[0] = $delivered_qty;
			
            if ($product_array[0] < $sc_qty)
                $product_array[1] = "PARTIALLY SATISFIED";
            else if ($product_array[0] >= $sc_qty)
                $product_array[1] = "FULLY SATISFIED";
        }
        else {
            $product_array[0] = 0;
            $product_array[1] = "OPEN";
        }
        return $product_array;
    }
}

class VoDOHeaderList {
    var $do_serialnumber;
    var $delivery_order_code;
    var $customer_serialnumber_fk;
    var $delivery_order_date;
    var $do_detserialnumber;
    var $sales_con_code;
    var $pro_serialnumber_fk;
	var $pro_detserialnumber;
	var $pro_name;
	var $pro_description;
    var $part_number;
    var $price_per_unit;
    var $delivered_qty;
	var $default_price;
	var $price_list;
    var $isSelected;
}

class VoDeliveryOrder {
    var $serialnumber;
    var $delivery_order_code;
    var $customer_serialnumber_fk;
    var $client_name;
    var $total_qty;
    var $delivery_order_date;
    var $do_remarks;
	var $is_invoiced;
    var $delivery_order_fk;
	var $do_detserialnumber;
	var $sc_serialnumber;
	var $sales_con_code;
    var $sc_detserialnumber_fk;
	var $pro_serialnumber_fk;
	var $pro_name;
	var $pro_description;
    var $part_number;
	var $reserved_qty;
	var $po_detserialnumber;
    var $sc_qty;
    var $delivered_qty;
    var $warehouse_serialnumber_fk;
    var $cre_userid_fk;
    var $cre_datetime;
    var $activestatus;
}

class VoTrasactionMaster 
{      
    var $serialnumber;
	var $gr_do_detserialnumber_fk;
	var $po_sc_detserialnumber_fk;
	var $pro_serialnumber_fk;
	var $trans_pro_qty;
	var $pro_status;
    var $trans_status;
	var $warehouse_serialnumber_fk;
    var $trans_type;
    var $trans_date;
    var $cre_userid_fk;
    var $cre_datetime;
    var $activestatus;
}

class VOPrice {
    var $sgd_price;
	var $other_price;
    var $hilight;
}

// $ss=new DeliveryOrderMaster();
// $ss->getAllDeliveryOrder();
?>